library Wave4 initializer init requires LegacySystem


	globals
		private rect  udg_CurrentLZ  = null
		private unit array BHDUnits
	endglobals
	

    private function BHDExtractionConditions takes nothing returns boolean
        return GetTriggerUnit()==BHDUnits[1] or GetTriggerUnit()==BHDUnits[2] or GetTriggerUnit()==BHDUnits[3]
    endfunction

    private function EnterBlackHawk takes unit u returns nothing
        call SetUnitOwner(u,Player(11),false)
        call RemoveGuardPosition(u)
        call IssuePointOrderLoc(u,"move",udg_LZPoint)
        call UnitRemoveAbility(u,'Aatk')
    endfunction

    private function BHDExtraction takes nothing returns nothing
        local integer A = 1
        local integer i = 1
        local integer SurvivorPoints = 0
        
        call DisableTrigger(GetTriggeringTrigger())
        
        call SetProximitySpawnEnabled(false)
        
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 8, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : Iron Hand, we've got the crew. Send in a bird now. Out." )
        set udg_ExtractionComplete = true
        set udg_IntenseSpawn = 0
        call PolledWait(5.)
        call GeneralText(5.0, "|cfff3ad00Battalion|r : Medevac's on its way." )
        if GetWidgetLife(BHDUnits[100])>0.405 then
            call IssuePointOrder(BHDUnits[100],"move",-533.0,-306.0)
        endif
        call PolledWait(7.)
        set udg_LZPoint = Location(-175.0,0.0)
        call GankLoc(udg_LZPoint,Player(11),'h009',1,2999,3000) //Black Hawk
        call PolledWait(0.33)
        set udg_BlackHawk = FirstOfGroup(GetUnitsOfTypeIdAll('h009'))
        call SetUnitScalePercent( udg_BlackHawk, 50.00, 50.00, 50.00 )
        call PolledWait(0.2)
        call IssuePointOrderLoc( udg_BlackHawk, "move", udg_LZPoint )
        call StartSound(gg_snd_BlackHawkRotor)
        call PolledWait(2.)
        call StartSound(gg_snd_BlackHawk)
        call PolledWait(3.25)
        call SetUnitFlyHeight(udg_BlackHawk,12.0,125.0)
        call SmoothUnitResize(udg_BlackHawk,1.45,1.55,4.25)
        call SetLandingAreaWindEnabled(true)
        call PolledWait(2.5)
        set i = GetRandomInt(1, udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 8, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : You're going to be fine." )
        //call SetUnitTimeScalePercent(udg_BlackHawk,65.0)
        call HeloShock(udg_BlackHawk)
        call BlackHawkWashOff.execute()
        call StartSound(gg_snd_BlackHawkLand)
        call PolledWait(2.)
        call KiloEvac(udg_BlackHawk)
        call EnterBlackHawk(BHDUnits[1])
        if (getInteger(null,"NumCorpsman")<1 and udg_Players>2) or GetWidgetLife(BHDUnits[1])<=0.405 then
            call EnterBlackHawk(BHDUnits[2])
            call EnterBlackHawk(BHDUnits[3])
        endif
        call PauseUnit(udg_BlackHawk,true)
        call PolledWait(5.)
        call PauseUnit(udg_BlackHawk,false)
        call StartSound(gg_snd_Loading)
        call KiloEvac(udg_BlackHawk)
        if GetWidgetLife(BHDUnits[1])>0.405 then
            set SurvivorPoints = SurvivorPoints + 10
        endif
        if GetWidgetLife(BHDUnits[2])>0.405 then
            set SurvivorPoints = SurvivorPoints + 5
        endif
        if GetWidgetLife(BHDUnits[3])>0.405 then
            set SurvivorPoints = SurvivorPoints + 5
        endif
        if GetWidgetLife(BHDUnits[1])<=0.405 then
            call SetPlayerHandicap(Player(13),GetPlayerHandicap(Player(13))+0.02)
            call SetPlayerHandicap(Player(14),GetPlayerHandicap(Player(14))+0.02)
        else
            call UnitRemoveItemFromSlot(BHDUnits[1],0)
            call UnitRemoveItemFromSlot(BHDUnits[1],1)
            call UnitRemoveItemFromSlot(BHDUnits[1],2)
            call RemoveUnit(BHDUnits[1])
        endif
        set A=2
        if (getInteger(null,"NumCorpsman")<1 and udg_Players>2) or GetWidgetLife(BHDUnits[1])<=0.405 then
            loop
                exitwhen A>3
                call UnitRemoveItemFromSlot(BHDUnits[A],0)
                call UnitRemoveItemFromSlot(BHDUnits[A],1)
                call UnitRemoveItemFromSlot(BHDUnits[A],2)
                call RemoveUnit(BHDUnits[A])
                set A=A+1
            endloop
            call PolledWait(5.)
            if SurvivorPoints>0 then
                call GeneralText(2.0, "|cfff3ad00Battalion|r : Extraction complete. These men owe you one." )
            endif
        else
            call UnitRemoveAbility(BHDUnits[2],'A02Q')
            call UnitRemoveAbility(BHDUnits[3],'A02Q')
            call PolledWait(5.)
            if SurvivorPoints>0 then
                call GeneralText(4.0, "|cfff3ad00Battalion|r : The pilot's going to be fine. The rest of the men will accompany your squad." )
            endif
        endif
        call BlackHawkWashOff.execute()
        call SetUnitFlyHeight(udg_BlackHawk, 500.00, 200.00)
        call SmoothUnitResize(udg_BlackHawk,1.55,1.45,3)
        call SetUnitTimeScalePercent(udg_BlackHawk,100.0)
		
        call IssuePointOrder( udg_BlackHawk, "move", 13000.0, 10000.0 )
        call PolledWait(2.)
        call SetLandingAreaWindEnabled(false)
        call EnumDestructablesInCircleBJ(600,udg_LZPoint,function TreeShakeEnd)
        call PolledWait(7.5)
        call RemoveUnit(udg_BlackHawk)
        call RemoveLocation(udg_LZPoint)
        set i=1
        if SurvivorPoints>0 and udg_Mode==1 then
            call ALICE2Text(10.0, "Survivors from crash site successfully rescued. |cff1e90ff" + I2S(SurvivorPoints) + " XP|r awarded to all Marines." )
            loop
                exitwhen i>udg_InitialPlayers
                if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                    set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + SurvivorPoints
                endif
                set i=i+1
            endloop
        endif
        if udg_CurrentWave==4 then
            call ExecuteRegisteredFunction("Wave5a")
           // call Wave5a.execute()
        endif
    endfunction

    private function BHDRescue takes nothing returns nothing
        local integer i = 1
        local trigger t
        local real x
        local real y
        local real dx
        local real dy
        local real dx2
        local real dy2
        local real dx3
        local real dy3
        loop
            exitwhen i > udg_Players
            set x = GetUnitX(udg_Hero[udg_Sorted[i]])
            set y = GetUnitY(udg_Hero[udg_Sorted[i]])
            set dx = GetUnitX(BHDUnits[1]) - x
            set dy = GetUnitY(BHDUnits[1]) - y
            set dx2 = GetUnitX(BHDUnits[2]) - x
            set dy2 = GetUnitY(BHDUnits[2]) - y
            set dx3 = GetUnitX(BHDUnits[3]) - x
            set dy3 = GetUnitY(BHDUnits[3]) - y
            if dx*dx+dy*dy<=62500.0 or dx2*dx2+dy2*dy2<=62500.0 or dx3*dx3+dy3*dy3<=62500.0 then //250 distance
                call DestroyTrigger(GetTriggeringTrigger())
                if GetWidgetLife(BHDUnits[1])<=0.405 and GetWidgetLife(BHDUnits[2])<=0.405 and GetWidgetLife(BHDUnits[3])<=0.405 then
                    call RadioChat(udg_Hero[udg_Sorted[i]], 10.0, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : The crew's all dead." )
                    exitwhen 1==1
                endif
                set t = CreateTrigger()
                call TriggerRegisterEnterRectSimple( t, gg_rct_Town )
                call TriggerAddCondition( t, Condition( function BHDExtractionConditions ) )
                call TriggerAddAction( t, function BHDExtraction )
                call SetProximitySpawnEnabled(true)
                set udg_IntenseSpawn = 1
                call StartSound(gg_snd_Rescue)
                call DisplayTextToPlayer( GetLocalPlayer(),0.0,0.0, "Black Hawk crew have been rescued by " + GetPlayerName(GetOwningPlayer(udg_Hero[udg_Sorted[i]])) )
                call SetUnitOwner(BHDUnits[1],GetOwningPlayer(udg_Hero[udg_Sorted[i]]),false)
                call SetUnitOwner(BHDUnits[2],GetOwningPlayer(udg_Hero[udg_Sorted[i]]),false)
                call SetUnitOwner(BHDUnits[3],GetOwningPlayer(udg_Hero[udg_Sorted[i]]),false)
               // call TriggerRegisterUnitEvent(gg_trg_Article_15, BHDUnits[1], EVENT_UNIT_DEATH)
               // call TriggerRegisterUnitEvent(gg_trg_Article_15, BHDUnits[2], EVENT_UNIT_DEATH)
               // call TriggerRegisterUnitEvent(gg_trg_Article_15, BHDUnits[3], EVENT_UNIT_DEATH)
                call UnitAddAbility(BHDUnits[1],'A00D')
                call UnitAddAbility(BHDUnits[2],'A00D')
                call UnitAddAbility(BHDUnits[3],'A00D')
                call PolledWait(2.)
                call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : That fracture looks bad." )
                call PolledWait(2.)
                call FieldChat(BHDUnits[1],3.0, "|cfff3ad00CWO Durant|r : Both of my crew chiefs are dead." )
                call PolledWait(2.)
                call SatelliteCamera()
                call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : We'll have to come back for the bodies later." )
                call PolledWait(4.)
                call FieldChat(BHDUnits[1],3.0, "|cfff3ad00CWO Durant|r : Let's get out of here. We have a fuel tank leak." )
                call PolledWait(8.)
                call StartSound(gg_snd_Explosion)
                set udg_myunit = CreateUnit(Player(11),'e007',GetUnitX(udg_BlackHawk),GetUnitY(udg_BlackHawk),0.0)
                call UnitApplyTimedLifeBJ(0.5,'BTLF',udg_myunit)
                call PauseUnit(udg_BlackHawk,false)
                call DestroyEffect(AddSpecialEffect( "Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl", GetUnitX(udg_BlackHawk), GetUnitY(udg_BlackHawk) ))
                call RemoveUnit(udg_BlackHawk)
                call PolledWait(2.)
                call MultiboardSetTitleText( udg_SquadStatus, "Iron Hand : Escort the survivors to town." )
                if getInteger(null,"NumCorpsman")>0 then
                    call GeneralText(4.0, "|cffcd950cBattalion|r : Bring the pilot to town. Have your Corpsman patch the Marines up." )
                elseif udg_Players<3 then
                    call GeneralText(4.0, "|cffcd950cBattalion|r : Bring the pilot to town. We'll send an MH-6 for extraction." )
                else
                    call GeneralText(4.0, "|cffcd950cBattalion|r : Bring the survivors to town. We'll send an MH-6 for extraction." )
                endif
                call PolledWait(4.)
                call GeneralText(5.0, "|cffcd950cMarine|r : Give us suppressive fire! Keep the crew moving." )
                call GankUnit(udg_Hero[udg_Sorted[i]],Player(13),'n004', 3*udg_Spawn ,1800,2500)
          exitwhen 1==1
            endif
            set i=i+1
        endloop
        if udg_CurrentWave!=4 then
            call DisableTrigger(GetTriggeringTrigger())
        endif
        set t = null
    endfunction


    private function GunshipEntry2 takes nothing returns nothing
        local real x = GetUnitX(udg_Boss)-2000.0
        local real y = GetUnitY(udg_Boss)-2000.0
        local unit u
        local unit u2
        local unit u3
        local group g = CreateGroup()
        call GeneralText(5.0, "|cffcd950cBattalion|r : Gunships are heading your way. They've been pursuing the Flesh Composite from Sector D." )
        set u = CreateUnit(Player(11),'hgyr',x,y,0.0)
        call GroupAddUnit(g,u)
        call TriggerSleepAction(0.)
        set u2 = CreateUnit(Player(11),'hgyr',x-220.0,y+220.0,0.0)
        call GroupAddUnit(g,u2)
        call TriggerSleepAction(0.)
        set u3 = CreateUnit(Player(11),'h001',x+220.0,y-220.0,0.0)
        call GroupAddUnit(g,u3)
        call StartSound(gg_snd_CobraRotor)
        call PolledWait(2.)
        call GeneralText(5.0, "|cfff3ad00Major Jamie Cox|r : We almost lost him a few clicks back and were about to head back." )
        call IssuePointOrder(u,"attack",GetUnitX(udg_Boss)+GetRandomReal(-400.0,400.0),GetUnitY(udg_Boss)+GetRandomReal(-400.0,400.0))
        call IssuePointOrder(u2,"attack",GetUnitX(udg_Boss)+GetRandomReal(-400.0,400.0),GetUnitY(udg_Boss)+GetRandomReal(-400.0,400.0))
        call IssuePointOrder(u3,"attack",GetUnitX(udg_Boss)+GetRandomReal(-400.0,400.0),GetUnitY(udg_Boss)+GetRandomReal(-400.0,400.0))
        set udg_soundpath = "war3mapImported\\AirSupport.mp3"
        call PlaySoundPath.execute()
        call PolledWait(3.)
        call SatelliteCamera()
        call PolledWait(2.)
        call GankMarine(Player(13),'n005', 2*udg_Spawn ,1800,2500)
        call GeneralText(5.0, "|cfff3ad00Major Jamie Cox|r : We've got visual. Steer clear of our Hellfires." )
        call PingMinimapEx(GetUnitX(udg_Boss), GetUnitY(udg_Boss), 5.00, 255, 0, 0, false)
        call PolledWait(30.0-(I2R(udg_Players)*4.0))
        call IssuePointOrder(u,"attack",GetUnitX(udg_Boss)+GetRandomReal(-400.0,400.0),GetUnitY(udg_Boss)+GetRandomReal(-400.0,400.0))
        call IssuePointOrder(u2,"attack",GetUnitX(udg_Boss)+GetRandomReal(-400.0,400.0),GetUnitY(udg_Boss)+GetRandomReal(-400.0,400.0))
        call IssuePointOrder(u3,"attack",GetUnitX(udg_Boss)+GetRandomReal(-400.0,400.0),GetUnitY(udg_Boss)+GetRandomReal(-400.0,400.0))
        call IssuePointOrder(u2,"move",GetUnitX(u2)+GetRandomReal(-400.0,400.0),GetUnitY(u2)+GetRandomReal(-400.0,400.0))
        call GankMarine(Player(13),'n005',2*udg_Spawn,1800,2500)
        call IssuePointOrder(u,"move",GetUnitX(u)+GetRandomReal(-400.0,400.0),GetUnitY(u)+GetRandomReal(-400.0,400.0))
        if udg_HitsTaken<30 then
            call GankMarine(Player(14),'n005',4*udg_Spawn,1800,2500)
        else
            call GankMarine(Player(14),'n004',4*udg_Spawn,1800,2500)
        endif
        call IssuePointOrder(u3,"move",GetUnitX(u3)+GetRandomReal(-300.0,300.0),GetUnitY(u3)+GetRandomReal(-300.0,300.0))
        call PolledWait(5.)
        call IssuePointOrder(u,"attack",GetUnitX(udg_Boss)+GetRandomReal(-500.0,500.0),GetUnitY(udg_Boss)+GetRandomReal(-500.0,500.0))
        call IssuePointOrder(u2,"attack",GetUnitX(udg_Boss)+GetRandomReal(-500.0,500.0),GetUnitY(udg_Boss)+GetRandomReal(-500.0,500.0))
        call IssuePointOrder(u3,"attack",GetUnitX(udg_Boss)+GetRandomReal(-500.0,500.0),GetUnitY(udg_Boss)+GetRandomReal(-500.0,500.0))
        call PolledWait(30.)
        call IssuePointOrder(u,"move",GetUnitX(u)+GetRandomReal(-350.0,350.0),GetUnitY(u)+GetRandomReal(-350.0,350.0))
        call PolledWait(5.)
        if FirstOfGroup(g)!=null then
            if GetRandomInt(1,3)==1 then
                call GeneralText(5.0, "|cfff3ad00Major Jamie Cox|r : Pulling out. Stay safe, and kill some bad guys." )
            else
                call GeneralText(5.0, "|cfff3ad00Major Jamie Cox|r : Stay safe, leathernecks. Returning to base." )
            endif
        endif
        call PolledWait(1.5)
        call GroupPointOrder(g,"move",14000.0,7000.0)
        call PolledWait(5.)
        call ForGroup(g,function RemoveUnitAll)
        call DestroyGroup(g)
        set g = null
        set u = null
        set u2 = null
        set u3 = null
    endfunction

    private function GunshipEntry takes nothing returns nothing
        local real currentlife = GetWidgetLife(udg_Boss)
        local real percentlife = currentlife/GetUnitState(udg_Boss,UNIT_STATE_MAX_LIFE)
        if (percentlife<0.75 and currentlife>0.405) or (udg_SquadXP<10000 and percentlife<0.9 and currentlife>0.405) then
            call DestroyTrigger(GetTriggeringTrigger())
            if udg_SquadXP>40000 and GetRandomInt(0,1)==1 then
                return
            endif
            call GunshipEntry2.execute()
        endif
    endfunction

    private function BlackHawkEntry takes location l, integer i, real r1, real r2 returns nothing
        local integer A = 1
        local real r = GetRandomReal(r1,r2)
        local real theta = GetRandomReal(0,6.28)
        local real ux = Clamp(GetLocationX(l)+r*Cos(theta),GetRectMinX(bj_mapInitialPlayableArea),GetRectMaxX(bj_mapInitialPlayableArea))
        local real uy = Clamp(GetLocationY(l)+r*Sin(theta),GetRectMinY(bj_mapInitialPlayableArea),GetRectMaxY(bj_mapInitialPlayableArea))
        set udg_BlackHawk = CreateUnit(Player(11),i,ux,uy,theta+3.14)
    endfunction

    private function Wave4b takes nothing returns nothing
        local unit u
        local trigger t = CreateTrigger()
        local integer i = 2
        local real x
        local real y

        set udg_CurrentWave = 4
        set udg_CurrentLZ = udg_LandingZones[GetRandomInt(3,8)]
        set udg_LZPoint = GetRectCenter(udg_CurrentLZ)
        call MoveRectToLoc(gg_rct_CurrentLZRegion,udg_LZPoint)
        set x = GetLocationX(udg_LZPoint)
        set y = GetLocationY(udg_LZPoint)
        set udg_Visibility = 71
        call IntermissionRestore()
        set udg_Visibility = 70
        call IntermissionRestore()
        call GenericActions.execute()
        call PolledWait(2.)
        call MultiboardSetTitleText( udg_SquadStatus, "Incoming Transmission.." )
        call StartSound(gg_snd_BlackHawkRotor)
        call PolledWait(2.)
        call GeneralText(2.5, "|cffcd950cSuper Six Four|r : We are experiencing engine failure." )
        call PolledWait(3.)
        call GeneralText(2.5, "|cffcd950cSuper Six Four|r : We're losing control. Prepare for emergency landing." )
        call StartSound(gg_snd_EngineFailure)
        call PolledWait(3.)
        call GeneralText(2.5, "|cffcd950cSuper Six Four|r : Six Four is going down. Six Four is going down." )
        call BlackHawkEntry(udg_LZPoint,'h009',2800,3000)
        call RemoveGuardPosition(udg_BlackHawk)
        call SetUnitScalePercent(udg_BlackHawk, 50.0, 50.0, 50.0)
        call TriggerSleepAction(0.)
        call IssuePointOrderLoc(udg_BlackHawk,"move",udg_LZPoint)
        call PolledWait(3.5)
        call MultiboardSetTitleText( udg_SquadStatus, "Sending Emergency Report to Iron Hand" )
        call LightningAmbience.execute()
        call SetUnitFlyHeight(udg_BlackHawk, 0.00, 150.0)
        call SmoothUnitResize(udg_BlackHawk,1.45,1.55,3.5)
        call PolledWait(3.5)
        call IssuePointOrderLoc( udg_BlackHawk, "move", udg_LZPoint )
        call StartSound(gg_snd_BlackHawkCrash)
        call BlackHawkWashOff.execute()
        call PolledWait(3.)
        set u = CreateUnitAtLoc(Player(11),'o002',udg_LZPoint,0.0)
        call UnitApplyTimedLife(u, 'Bhwd', 180.0)
        call BlackHawkWashOff.execute()
        call SetUnitMoveSpeed(udg_BlackHawk,1.0)
        call PlaySoundAtPointBJ( gg_snd_BlackHawkLand, 100.00, udg_LZPoint, 15.0 )
        call PolledWait(1.5)
        call SetUnitTimeScalePercent(udg_BlackHawk,0.01)
        call TriggerSleepAction(0.)
        call PauseUnit(udg_BlackHawk,true)
		
		
        set BHDUnits[1] = CreateUnit(Player(11),'z006',x+GetRandomReal(-250.0,250.0),y+GetRandomReal(-250.0,250.0),0.0)
        call SetWidgetLife(BHDUnits[1],216.0)
		call UnitRemoveAbility(BHDUnits[1], 'A050') // remove control aircraft
        call SetLoadState(I2S(GetHandleId(BHDUnits[1])),1)
        call UnitAddItemById(BHDUnits[1], 'I004') //Medkit
        call UnitAddAbility(BHDUnits[1], 'A01J') //Fracture
        call IssueTargetOrder(BHDUnits[1],"slow",BHDUnits[1])
        set udg_AITarget=BHDUnits[1]
        loop
            exitwhen i>3
            call TriggerSleepAction(0.)
            set BHDUnits[i] = CreateUnit(Player(11),'z008',x+GetRandomReal(-250.0,250.0),y+GetRandomReal(-250.0,250.0),0.0)
            call SetWidgetLife(BHDUnits[i],GetRandomReal(150.0,220.0))
            call SetLoadState(I2S(GetHandleId(BHDUnits[i])),1)
            call UnitAddAbility(BHDUnits[i], 'A01J') //Fracture
            if GetRandomInt(0,2)==1 then
                call IssueTargetOrder( BHDUnits[i], "slow", BHDUnits[i] )
            endif
            set udg_myloc = Location(x + GetRandomReal(-250.0,250.0), y + GetRandomReal(-250.0,250.0))
            call CreatePermanentCorpseLocBJ( bj_CORPSETYPE_FLESH, 'z000', Player(11), udg_myloc, GetRandomReal(0.0,360.0) )
            set u = CreateUnit(Player(11),'o002',x+GetRandomReal(-250.0,250.0),y+GetRandomReal(-250.0,250.0),0.0)
            call UnitApplyTimedLife(u,'Bhwd',150.0)
            call CreateItem('I018',x+GetRandomReal(-250.0,250.0),y+GetRandomReal(-250.0,250.0)) //Marine Corpse
            call CreateUbersplatBJ( udg_myloc, "HCRT", 100, 100, 100, 0, false, true )
            call ShowUbersplat(GetLastCreatedUbersplat(),true)
            call RemoveLocation(udg_myloc)
            set i=i+1
        endloop
        call TriggerRegisterTimerEvent(t,5.0,true)
        call TriggerAddAction(t,function BHDRescue)
        set t = null
        set udg_IntenseSpawn = 1
        call PolledWait(2.5)
        call UnitRemoveAbility(BHDUnits[1],'A01J') //Fracture
        call UnitRemoveAbility(BHDUnits[2],'A01J')
        call UnitRemoveAbility(BHDUnits[3],'A01J')
        
        call RegisterUnitForAilmentChecks(BHDUnits[1])
        call RegisterUnitForAilmentChecks(BHDUnits[2])
        call RegisterUnitForAilmentChecks(BHDUnits[3])
        
        call MultiboardSetTitleText( udg_SquadStatus, "Receiving Orders.." )
        call GankUnit(BHDUnits[1],Player(13),'u00L',8,500,1200)
        call StartSound(gg_snd_SatelliteImaging)
        call SetCameraQuickPosition(x,y)
        call PingMinimapEx(x,y,45.0,255,0,0,false)
        call GeneralText(4.0, "|cffcd950cBattalion|r : Get to the crash site and check for survivors." )
        call PolledWait(2.5)
        call LightningAmbience.execute()
        call GeneralText(2.5, "|cffcd950cMarine|r : Roger that." )
        call PolledWait(2.5)
        call GeneralText(4., "|cffcd950cBattalion|r : Well move quick, Zulus will be coming down on top of them." )
        //call MicroWeather('WOlw',udg_LZPoint,600.0,80.0)
        set i=1
        loop
            exitwhen i>udg_Players
            set u = CreateUnit(ConvertedPlayer(udg_Sorted[i]),'e002',x+70.0,y-120.0,0.0)
            call UnitApplyTimedLife(u,'Bhwd',25.0)
            call TriggerSleepAction(0.)
            set i=i+1
        endloop
        set u = null
        call RandomSpawn('n00N',1,GetRandomInt(0,1)) //Mass HP Zombie
        call SpawnRectRandom(gg_rct_SpawnEastCave,Player(14),'nzom',2+udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(13),'nzom',2+udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(14),'nzom',2+udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnWestCave,Player(13),'nzom',2+udg_Spawn)
        call GeneralText(3.0, "|cffcd950cMarine|r : If there's anyone alive, they're going to need our help real quick." )
        call PolledWait(8.)
        call MultiboardSetTitleText( udg_SquadStatus, "Investigate UH-60 Crash Site" )
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Investigate UH-60 Crash Site" )
        call QuestSetDescription(udg_CurrentOrders, "Link up with survivors from the crash site. Provide immediate medical assistance and bring them to town for extraction." )
        call ALICE2Text(5.0, "|cff8b864eNew Objective|r : Link up with survivors from the crash site." )
        call MissionUpdate.execute()
        call PolledWait(60.)
        call GankUnit(BHDUnits[1],Player(13),'nzom',8,500,1500)
        if udg_SquadXP>100000 then
            call GankUnit(BHDUnits[2],Player(13),'nsw1',4,500,1500)
        endif
        call PolledWait(80.0+150.0*udg_Pace)
        if udg_CurrentWave==4 and udg_ExtractionComplete==false then
            if GetWidgetLife(BHDUnits[1])>0.405 or GetWidgetLife(BHDUnits[2])>0.405 or GetWidgetLife(BHDUnits[3])>0.405 then
                call GeneralText(7.5, "Black Hawk Crew have died due to excessive blood loss." )
            endif
            call SetPlayerHandicap(Player(13),GetPlayerHandicap(Player(13))+0.03)
            call SetPlayerHandicap(Player(14),GetPlayerHandicap(Player(14))+0.03)
            call RandomSpawn('n002',1,udg_Spawn) //Devourer
            call KillUnit(BHDUnits[1])
            call KillUnit(BHDUnits[2])
            call KillUnit(BHDUnits[3])
            call KillUnit(udg_BlackHawk)
            call PolledWait(10.)
            call ExecuteRegisteredFunction("Wave5a")
           // call Wave5a.execute()
        endif
        call RemoveLocation(udg_LZPoint)
    endfunction

    private function Wave4a takes nothing returns nothing 
        local integer i = 1
        local trigger t = CreateTrigger()
        local location l = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        local group g = CreateGroup()
        local unit u
        local real x
        local real y
        local real dx
        local real dy
        local real xcore = -1750.0
        local real ycore = -575.0
        loop
            set x = GetLocationX(l)
            set y = GetLocationY(l)
            set dx = x-GetUnitX(udg_Residence41)
            set dy = y-GetUnitY(udg_Residence41)
            exitwhen dx*dx+dy*dy>12250000.0 //3500 radius
            call RemoveLocation(l)
            set l = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        endloop
        set udg_Boss = CreateUnit(Player(14),'uabo',x,y,0.0)
        call TriggerRegisterUnitEvent(t,udg_Boss,EVENT_UNIT_ATTACKED)
        call TriggerAddAction(t,function GunshipEntry)
        call RemoveLocation(l)
        set l = null
        set t = null
        set udg_CurrentWave = 4
        set udg_Visibility = 71
        call IntermissionRestore()
        set udg_Visibility = 70
        call IntermissionRestore()
        call GenericActions.execute()
        call SetNoise(6.0)
        call PolledWait(0.25)
        set udg_soundpath = "Sound\\Ambient\\DoodadEffects\\SargerasRoar.wav"
        call PlaySoundPath.execute()
        call PolledWait(3.25)
        call ClearNoise()
        call CameraSetTargetNoiseForPlayer(GetLocalPlayer(),4.00,0.02)
        call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(13),'n005',udg_Spawn)
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(14),'n005',udg_Spawn)
        // Ogilvy rounds up the townsfolk
        call FieldChat(udg_Ogilvy, 5.0, "|cfff3ad00Ogilvy|r : All of you heard that. Let's move to a safer area and let the Marines do their job." )
        call PolledWait(2.)
        call GroupEnumUnitsOfPlayer(g,Player(9),null)
        if GetRandomInt(0,1)==1 then
            set xcore = -1560.0
            set ycore = 1215.0
        endif
        if udg_SquadXP>130000 then
            call RandomSpawn('n016',1,udg_Spawn) //Invi Worm
        endif
        call FieldChat(udg_Ogilvy, 5.0, "|cfff3ad00Ogilvy|r : Stay out of harm's way. Avoid contact with.. the infected." )
        call RemoveAllGuardPositions(Player(9))
        loop
            set u = FirstOfGroup(g)
            exitwhen u==null
            set x = xcore+GetRandomReal(-75.0,75.0)
            set y = ycore+GetRandomReal(-75.0,75.0)
            if u!=udg_Ogilvy then
                call UnitRemoveAbility(u,'Aatk')
            endif
            call IssuePointOrder(u,"move",x,y)
            call GroupRemoveUnit(g,u)
        endloop
        call DestroyGroup(g)
        set g = null
        if GetWidgetLife(BHDUnits[100])>0.405 then
            set x = xcore+GetRandomReal(-120.0,120.0)
            set y = ycore+GetRandomReal(-120.0,120.0)
            call IssuePointOrder(BHDUnits[100],"move",x,y)
        endif
        if GetWidgetLife(BHDUnits[101])>0.405 then
            set x = xcore+GetRandomReal(-120.0,120.0)
            set y = ycore+GetRandomReal(-120.0,120.0)
            call IssuePointOrder(BHDUnits[101],"move",x,y)
        endif
        call PolledWait(50.0*udg_Pace)
        set i=1
        loop
            exitwhen i>udg_Players
            if udg_Experience[udg_Sorted[i]]<500 then
                call DisplayTimedTextToPlayer(ConvertedPlayer(udg_Sorted[i]),0.0,0.0,10.0,"Input Z-G to turn on Night Vision Goggles if it gets too dark.")
            endif
            set i=i+1
        endloop
        set i=1
        call GankMarine(Player(13),'n005',3*udg_Spawn,1800,2500)
        call PolledWait(40.0*udg_Pace)
        call FieldChat(udg_Ogilvy, 6.0, "|cfff3ad00Ogilvy|r : This virus is creating monsters. I don't understand...where could such a thing originate from?" )
        if udg_Players>=5 then
            call GankMarine(Player(14),'nzom',2*udg_Spawn,1800,2500)
        endif
        call PolledWait(20.0*udg_Pace)
        call FieldChat(udg_Ogilvy, 5.0, "|cfff3ad00Ogilvy|r : We can't stay here long. We MUST evacuate these people." )
        call LightningAmbience.execute()
        call PolledWait(10.0*udg_Pace)
        if udg_Players>0 then
            call ExecuteRegisteredFunction("Wave5a")
            // call Wave5a.execute()
        endif
    endfunction



    private function init takes nothing returns nothing
        call RegisterFunction("Wave4a", function Wave4a)
        call RegisterFunction("Wave4b", function Wave4b)
    endfunction

endlibrary